import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestMars{
	public static void main(String args[]) throws Exception{

		MarsCar car = new MarsCar();

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String msg = "";
		while (null != (msg = br.readLine())) {
			if (msg.startsWith("replay")) {
				String msgs[] = msg.split(" ");
				ReplayCarDao dao = new ReplayCarDao();
				BlackBox bb = dao.query(Integer.parseInt(msgs[1]));
				ReplayCar.replayMove(bb);
				continue;
			}

			String msgs[] = msg.split(" ");
			car.move(msgs);
		}
	}
}